<template>
  <div class="layer" v-if="show" @touchmove.stop="preventD">
    <div class="dialog">
      <div class="dialog-container">
        <img :src="icons.awardCodeBg" mode="widthFix"/>
        <div class="code-section">
          <div>
            <div class="title">获得抽奖码</div>
            <div class="code">{{code}}</div>
            <a class="btn" @click="onShareClick">分享赚金币</a>
          </div>
        </div>
      </div>
      <icon type="cancel" size="30" color="#fff" @click="hideDialog"/>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    show: {
      type: Boolean,
      default: false
    },
    code: String
  },
  data () {
    return {
      icons: {
        awardCodeBg: `${require('static/images/award-code-bg.png')}`,
      },
    }
  },
  watch: {
    show (val) {
      val ? this.$emit('onShow') : this.$emit('onHide')
    }
  },
  methods: {
    preventD () {},
    hideDialog () {
      this.$emit('update:show', false)
    },
    onClick () {
      this.$emit('onClick')
      this.hideDialog()
    },
    onShareClick () {
      this.$emit('onShareClick')
    }
  }
}
</script>

<style lang="less" scoped>
.layer {
  z-index: 200;
  position: fixed;
  top: 0;
  width: 100%;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(0, 0, 0, .5);
  .dialog {
    width: 100%;
    text-align: center;
    &-container {
      position: relative;
      margin: 0 50rpx 60rpx;
      border-radius: 8rpx;
    }
    .code-section {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      display: flex;
      justify-content: center;
      align-items: center;
      color: #fff;
      .title {
        font-size: 32rpx;
      }
      .code {
        font-size: 44rpx;
        margin-top: 20rpx;
      }
      .btn {
        display: inline-block;
        margin-top: 40rpx;
        padding: 0 60rpx;
        height: 80rpx;
        line-height: 80rpx;
        font-size: 34rpx;
        color: #fff;
        border-radius: 40rpx;
        background-color: #dba912;
        &:active {
          background-color: #b5971f;
        }
      }
    }
  }
}
</style>
